import entity.customer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import service.customerService;

import java.util.List;
import java.util.Scanner;

/**
 * @program: crm
 * @description: 测试类
 * @author:波
 * @create: 2020-05-18 15:38
 **/

public class cusomerTestt {
    public static void main(String[] args) {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("appcationContext.xml");
        customerService customerService=applicationContext.getBean("customerServiceImpl", customerService.class);
        Scanner input=new Scanner(System.in);
        do {
            System.out.println();
            System.out.println();
            System.out.println("1.查询所有信息");
            System.out.println("2.按名字查询所有信息");
            System.out.println("3.根据删除信息");
            System.out.println("4.新增信息");
            System.out.println("0,退出");
            System.out.println("请输入");
            int shuru=input.nextInt();
            switch (shuru){
                case 1:
                    List<customer> customers= customerService.getCustomers();
                    for (customer customer : customers) {
                        System.out.println(customer);
                    }
                    break;
                case 2:
                    System.out.println();
                    System.out.println("请输入用户名字（支持模糊查询）");
                    String name=input.next();
                    List<customer> customers2= customerService.getCustmoersByName("小");
                    for (customer customer : customers2) {
                        System.out.println(customer);
                    }
                    break;
                case 3:
                    System.out.println();
                    System.out.println("请输入用户Id");
                    int id=input.nextInt();
                    int count2=customerService.deleteCutomerById(id);
                    if(count2>0){
                        System.out.println("删除成功");
                    }else{
                        System.out.println("删除失败");
                    }
                    break;
                case 4:
                    System.out.println("新增用户信息");
                    System.out.println("请输入用户名称");
                    customer customer=new customer();
                    customer.setName(input.next());
                    System.out.println("请输入电话");
                    customer.setTelephone(input.next());
                    System.out.println("请输入地址");
                    customer.setAddress(input.next());
                    System.out.println("请输入用户类型Id");
                    customer.setTypeId(input.nextInt());
                    System.out.println("请输入用户备注");
                    customer.setRemark(input.next());
                    int ha=customerService.addCutomer(customer);
                    if(ha>0){
                        System.out.println("新增成功");
                    }else{
                        System.out.println("新增失败");
                    }
                    break;
                case 0:
                    return;
            }
        }while(true);
    }
}
